home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / xerox_4020 / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1988-08-01  |  3.5 KB  |  127 lines

  1. /*
  2.     Transfer routine for Xerox_4020 driver.
  3.     David Berezowski - October/87.
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9. #include "../printer/prtgfx.h"
  10.  
  11. Transfer(PInfo, y, ptr, colors)
  12. struct PrtInfo *PInfo;
  13. UWORD y;    /* row # */
  14. UBYTE *ptr;    /* ptr to buffer */
  15. UWORD *colors; /* indexes to color buffers */
  16. {
  17.     extern struct PrinterData *PD;
  18.  
  19.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  20.     UBYTE *dmatrix, *bptr, *yptr, *mptr, *cptr;
  21.     UBYTE dvalue, Black, Yellow, Magenta, Cyan, threshold;
  22.     UBYTE bit, y3;
  23.     union colorEntry *ColorInt;
  24.     UWORD x, x3, width, sx, *sxptr;
  25.  
  26.     /* pre-compute */
  27.     /* printer specific */
  28.     y3 = y & 3;
  29.     bptr = ptr + colors[y3];
  30.     yptr = ptr + colors[4 + y3];
  31.     mptr = ptr + colors[8 + y3];
  32.     cptr = ptr + colors[12 + y3];
  33.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  34.     x = PInfo->pi_xpos; /* get starting x position */
  35.     ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  36.     sxptr = PInfo->pi_ScaleX;
  37.     width = PInfo->pi_width; /* get # of source pixels */
  38.  
  39.     /* pre-compute threshold; are we thresholding? */
  40.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  41.         dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  42.         do { /* for all source pixels */
  43.             /* pre-compute intensity values for Black component */
  44.             Black = ColorInt->colorByte[PCMBLACK];
  45.             ColorInt++; /* bump ptr for next time */
  46.  
  47.             sx = *sxptr++;
  48.  
  49.             do { /* use this pixel 'sx' times */
  50.                 /* if should render black */
  51.                 if (Black > dvalue) {
  52.                     /* set bit in black buffer */
  53.                     *(bptr + (x >> 3)) |= bit_table[x & 7];
  54.                 }
  55.                 ++x; /* done 1 more printer pixel */
  56.             } while (--sx);
  57.         } while (--width);
  58.     }
  59.     else { /* not thresholding, pre-compute ptr to dither matrix */
  60.         dmatrix = PInfo->pi_dmatrix + (y3 << 2);
  61.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  62.             do { /* for all source pixels */
  63.                 /* pre-compute intensity values for Black */
  64.                 Black = ColorInt->colorByte[PCMBLACK];
  65.                 ColorInt++; /* bump ptr for next time */
  66.  
  67.                 sx = *sxptr++;
  68.  
  69.                 do { /* use this pixel 'sx' times */
  70.                     /* if should render black */
  71.                     if (Black > dmatrix[x & 3]) {
  72.                         /* set bit in black buffer */
  73.                         *(bptr + (x >> 3)) |=
  74.                             bit_table[x & 7];
  75.                     }
  76.                     ++x; /* done 1 more printer pixel */
  77.                 } while (--sx);
  78.             } while (--width);
  79.         }
  80.         else { /* color */
  81.             do { /* for all source pixels */
  82.                 /* pre-compute intensity vals for each color */
  83.                 Black = ColorInt->colorByte[PCMBLACK];
  84.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  85.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  86.                 Cyan = ColorInt->colorByte[PCMCYAN];
  87.                 ColorInt++; /* bump ptr for next time */
  88.  
  89.                 sx = *sxptr++;
  90.  
  91.                 do { /* use this pixel 'sx' times */
  92.                     /* pre-compute 'byte to set' value */
  93.                     x3 = x >> 3;
  94.                     /* pre-compute 'bit to set' val */
  95.                     bit = bit_table[x & 7];
  96.                     /* pre-compute dither value */
  97.                     dvalue = dmatrix[x & 3];
  98.                     /* if should render black */
  99.                     if (Black > dvalue) {
  100.                         /* set bit in black buffer */
  101.                         *(bptr + x3) |= bit;
  102.                     }
  103.                     /* black not rendered, check color */
  104.                     else  {
  105.                         /* if should render yellow */
  106.                         if (Yellow > dvalue) {
  107.                             /* set bit in Y buf */
  108.                             *(yptr + x3) |= bit;
  109.                         }
  110.                         /* if should render magenta */
  111.                         if (Magenta > dvalue) {
  112.                             /* set bit in M buf */
  113.                             *(mptr + x3) |= bit;
  114.                         }
  115.                         /* if should render cyan */
  116.                         if (Cyan > dvalue) {
  117.                             /* set bit in C buf */
  118.                             *(cptr + x3) |= bit;
  119.                         }
  120.                     }
  121.                     ++x; /* done 1 more printer pixel */
  122.                 } while (--sx);
  123.             } while (--width);
  124.         }
  125.     }
  126. }
  127.